﻿<UserControl x:Class="Comet.View.Wpf.DataMembersView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:c="clr-namespace:Comet.View.Wpf.Converters"
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             mc:Ignorable="d" 
             Width="650" Height="650"
             d:DesignHeight="300" d:DesignWidth="500"                         
             >
    <UserControl.Resources>
        <!-- Icons of the data members-->
        <BitmapImage x:Key="FieldInternalAccess" UriSource="./Icons/Field_Internal.png" />
        <BitmapImage x:Key="FieldPrivateAccess" UriSource="./Icons/Field_Private.png" />
        <BitmapImage x:Key="FieldProtectedAccess" UriSource="./Icons/Field_Protected.png" />
        <BitmapImage x:Key="FieldPublicAccess" UriSource="./Icons/Field_Public.png" />
        <BitmapImage x:Key="PropertyInternalAccess" UriSource="./Icons/Property_Internal.png" />
        <BitmapImage x:Key="PropertyPrivateAccess" UriSource="./Icons/Property_Private.png" />
        <BitmapImage x:Key="PropertyProtectedAccess" UriSource="./Icons/Property_Protected.png" />
        <BitmapImage x:Key="PropertyPublicAccess" UriSource="./Icons/Property_Public.png" />

        <!-- Converts the key of a resource to the resource itself -->
        <c:DataMemberToResourceConverter x:Key="DataMemberToResourceConverter"/>

        <!-- Stretches the ListViewItems content -->
        <Style TargetType="{x:Type ListViewItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ListView Name="listView" Grid.Row="1">
            <ListView.Resources>
                <!-- A sortable and groupable collection view source -->
                <CollectionViewSource x:Key="Data" Source="{Binding Path=DataMembers}">
                    <CollectionViewSource.SortDescriptions>
                        <scm:SortDescription PropertyName="Name" />
                    </CollectionViewSource.SortDescriptions>
                </CollectionViewSource>
            </ListView.Resources>

            <!-- We have to specify the source after the resource definition, in order to have the "Data" reosource -->
            <ListView.ItemsSource>
                <Binding Source="{StaticResource Data}" />
            </ListView.ItemsSource>

            <!-- Specify the group style of this list view -->
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <Expander Header="{Binding Path=Name}" IsExpanded="True">
                                            <ItemsPresenter />
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>

            <!-- The view (GridView) -->
            <ListView.View>
                <GridView>
                    <!-- The column "Name" -->
                    <GridViewColumn Header="Name" Width="Auto">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding Path=IsSelected}">
                                    <StackPanel Orientation="Horizontal">
                                        <Image Source="{Binding Path=., Converter={StaticResource DataMemberToResourceConverter}, Mode=OneWay}" 
                                               Width="16" 
                                               Height="16"/>
                                        <TextBlock Text="{Binding Path=Name}" />
                                    </StackPanel>
                                </CheckBox>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <!-- The column "Type" -->
                    <GridViewColumn Header="Type" Width="Auto">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Foreground="Gray" Text="{Binding Path=TypeName}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <StackPanel Grid.Row="2" Margin="5" Orientation="Horizontal" FlowDirection="RightToLeft">
            <Button Width="50" Height="30" Name="cancelButton" Click="cancelButton_Click">Cancel</Button>
            <Button Width="50" Height="30" Margin="3,0,0,0" Name="okButton" Click="okButton_Click">OK</Button>            
        </StackPanel>
    </Grid>
</UserControl>
